Kinetis SDK API Reference Manual  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Software Timer (SWT)

The Kinetis SDK provides a Software Timer (SWT) for timeout and delay. More...

Typedefs

typedef int32_t time_counter_t
 Data type of the counter of each timer channel. More...
 
typedef uint32_t time_free_counter_t
 Data type of the free running counter. More...
 

Enumerations

enum  sw_timer_channel_status_t {
  kSwTimerChannelExpired = 0x00,
  kSwTimerChannelStillCounting = 0x01,
  kSwTimerChannelIsDisable = 0x02,
  kSwTimerChannelNotAvailable = 0xFF
}
 Definition of the possible status of a software channel timer. More...
 
enum  _sw_timer_errors {
  kSwTimerStatusSuccess,
  kSwTimerStatusFail,
  kSwTimerStatusInvalidChannel
}
 List of status and errors. More...
 
enum  sw_timer_timeouts { kSwTimerMaxTimeout = 2147483647 }
 Max timeout value according to size of the time counter.
 

Functions

uint32_t sw_timer_init_service (void)
 Initializes the software timer module. More...
 
void sw_timer_shutdown_service (void)
 Deinitializes the software timer module. More...
 
uint8_t sw_timer_reserve_channel (void)
 Reserves a free timer channel to be used by any module and returns its identifier. More...
 
sw_timer_channel_status_t sw_timer_get_channel_status (uint8_t timerChannel)
 Returns the actual status of the given timer channel. More...
 
uint32_t sw_timer_start_channel (uint8_t timerChannel, time_counter_t timeout)
 Starts the count down of the given timer channel. More...
 
uint32_t sw_timer_release_channel (uint8_t timerChannel)
 Releases the given timer channel, so it can be used by someone else. More...
 
time_free_counter_t sw_timer_get_free_counter (void)
 Gets the current value of the free running counter. More...
 
void sw_timer_update_counters (void)
 This function is called every 1ms by the interruption and update count down values of all timer channels. More...
 

Typedef Documentation

typedef int32_t time_counter_t

If it is an int8_t the counter will count up to 127ms, int16_t up to 32767ms and int32_t up to 2147483647ms.

typedef uint32_t time_free_counter_t

This data type should be unsigned and will count up to 255ms if it is uint8_t, 65535ms for uint16_t and 4294967295ms for uint32_t.

Enumeration Type Documentation

Enumerator
kSwTimerChannelExpired 

Indicates the timer channel has counted the given ms.

kSwTimerChannelStillCounting 

Indicates the timeout of the channel has not expired and the timer is still counting.

kSwTimerChannelIsDisable 

Indicates the timer channel is not reserved.

kSwTimerChannelNotAvailable 

Indicates there are not available channels to reserve or the requested channel is not available.

Enumerator
kSwTimerStatusSuccess 

The execution was successful.

kSwTimerStatusFail 

The execution failed.

kSwTimerStatusInvalidChannel 

The given channel is not valid.

Valid channels are 0 to (SW_TIMER_NUMBER_CHANNELS - 1).

Function Documentation

uint32_t sw_timer_init_service ( void  )

Prepares variables and HAL layer to provide timer services. Starts the free running counter which will be available to get its value any time while the service is running; it is useful whenever a module wants to keep track of time, but do not wants to reserve a channel.

Returns
status_t Returns software timer status after initialization.
Return values
kSwTimerStatusSuccessThe initialization was successful and the software timer is ready to provide services.
kSwTimerStatusFailThe initialization failed.
void sw_timer_shutdown_service ( void  )

Shutdown HAL layer, so no timer service can be provided after the execution of this function.

Returns
void
uint8_t sw_timer_reserve_channel ( void  )
Returns
uint8_t Returns the number of the channel that was reserved.
Return values
Anyvalue between 0 and SW_TIMER_NUMBER_CHANNELS is a valid channel. It indicates the channel was reserved and can be used.
kSwTimerChannelNotAvailableIf there is not any available channel, because all channels are already reserved.
sw_timer_channel_status_t sw_timer_get_channel_status ( uint8_t  timerChannel)

The timer has to be previously started to return a valid status.

Parameters
timerChannel[in] Indicates the timer channel which status is going to be returned.
Returns
sw_timer_channel_status_t Current status of the given timer channel.
Return values
kSwTimerChannelExpiredIndicates the timer channel has counted the given ms.
kSwTimerChannelStillCountingIndicates the timeout of the channel has not expired and the timer is still counting.
kSwTimerChannelIsDisableIndicates the timer channel is not reserved.
kSwTimerChannelNotAvailableIndicates the timer channel is invalid.
uint32_t sw_timer_start_channel ( uint8_t  timerChannel,
time_counter_t  timeout 
)

The timer channel has to be previously reserved.

Parameters
timerChannel[in] Indicates the timer channel that is going to be started.
timeout[in] Time in ms that the timer channel will count. The timeout should be a multiple of count unit of the timer, otherwise it will be taken the integer part of the division and the exact count will not be achieved
Returns
status_t Reports failures in the execution of the function.
Return values
kSwTimerStatusSuccessA channel was started successfully.
kSwTimerStatusInvalidChannelThe timer channel is invalid, it does not exist.
uint32_t sw_timer_release_channel ( uint8_t  timerChannel)
Parameters
timerChannel[in] Identifier of the timer channel.
Returns
status_t Reports failures in the execution of the function.
Return values
kSwTimerStatusSuccessA channel was released successfully.
kSwTimerStatusInvalidChannelThe timer channel is invalid, it does not exist.
time_free_counter_t sw_timer_get_free_counter ( void  )

Any module can keep track of the time by reading this counter and calculates time difference. No reservation of timer channel is needed. Consider for calculations that when the counter overflows it will start from 0 again.

Returns
time_free_counter_t Returns current count of the free running counter.
void sw_timer_update_counters ( void  )
Returns
void